<template>
    <div v-loading="loading" element-loading-text="登录中..." element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.6)" class="login-container">
   
      <el-form :model="loginForm" :rules="rules" class="login-form" auto-complete="on" >
        <!-- 头像区域 -->
        <div v-if="TxStatus" class="avatar-box">
          <img src="../../assets/touxiang.jpg" alt="">
        </div>
        <div class="title-container">
          <h3 class="title">后台管理系统</h3>
        </div>
        <el-form-item prop="username">
          <span class="svg-container">
            <el-icon><User /></el-icon>
          </span>
          <el-input ref="username" v-model="loginForm.username" placeholder="请输入账号"
           name="username" type="text" tabindex="1" auto-complete="on" />
        </el-form-item>
        <el-form-item prop="password">
          <span class="svg-container">
            <el-icon><Lock /></el-icon>
          </span>
          <el-input v-model="loginForm.password" type="password" 
          placeholder="请输入密码" name="password" tabindex="2" auto-complete="on" @keyup.enter.native="handleLogin" />
          <span class="show-pwd" @click="showPwd">
            <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
        <div>
          <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:20px;" 
          @click.native.prevent="login">登录</el-button>
        </div>
      </el-form>
    </div>
  </template>
   
  <script setup>
  // 引入去除空格工具
  import { validUsername } from '@/utils/validate'
  import userApi from '../api/public/public.js'
  import { ElMessageBox,ElMessage} from 'element-plus'
  import {reactive} from 'vue'
  import Cookies from 'js-cookie'
  import {useRouter} from 'vue-router'
  const router=useRouter();


  let loginForm=reactive({
    username:"",
    sex:""
   });
   
  function login(){
     userApi.login(loginForm).then(response=>{
      console.log(response);
      if (response.data.code === 20001) {
        ElMessage({
          message: response.data.message,
          type: 'error',
          duration: 5 * 1000
         })
      } else {
        Cookies.set('token', response.data.data.token, { expires: 1 });
        
        router.push("/");
      }
    })
   }
  </script>
   
  <style lang="scss">
  $bg: #283443;
  $light_gray: #fff;
  $cursor: #fff;
  @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
    .login-container .el-input input {
      color: $cursor;
    }
  }
  .login-container {
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;
      input{
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        caret-color: $cursor;
        &:-webkit-autofill {
          box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: $cursor !important;
        }
      }
      :deep(.el-input__wrapper){
        // 如果没有下面这一行样式的话 无法对border进行自定义修改
        box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;
        border: none; /* 对border进行样式修改 */
        background-color: transparent;
      }
    }
    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
  }
 
 
  </style>
  <style lang="scss" scoped>
  $bg: #2d3a4b;
  $dark_gray: #889aa4;
  $light_gray: #eee;
   
  .login-container {
    min-height: 100%;
    width: 100%;
    overflow: hidden;
    background: url(@/assets/login-bg.jpg);
    background-size: 100% 100%;
     // 头像
    .avatar-box {
      margin: 0 auto;
      width: 120px;
      height: 120px;
      border-radius: 50%;
      border: 1px solid #409eff;
      box-shadow: 0 0 10px #409eff;
      position: relative;
      bottom: 20px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
   
    .login-form {
      position: relative;
      width: 520px;
      max-width: 100%;
      padding: 160px 35px 0;
      margin: 0 auto;
      overflow: hidden;
   
    }
   
    .tips {
      font-size: 18px;
      text-align: center;
      color: #000;
      margin-bottom: 10px;
    }
   
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
    }
   
    .title-container {
      position: relative;
   
      .title {
        font-size: 30px;
        color: $light_gray;
        margin: 0px auto 40px auto;
        text-align: center;
        font-weight: 500;
      }
    }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
  }
::v-deep.el-form{
    .el-input__wrapper{
        border:none; // 对边框进行修改
        background-color: transparent;
        box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;

    }
}



  </style>
  